package com.ikingtech.platform.service.system.role.service;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ikingtech.framework.sdk.utils.Tools;
import com.ikingtech.platform.service.system.role.entity.RoleDataScopeDO;
import com.ikingtech.platform.service.system.role.mapper.RoleDataScopeMapper;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author tie yan
 */
@Service
public class RoleDataScopeRepository extends ServiceImpl<RoleDataScopeMapper, RoleDataScopeDO> {

    public void removeByRoleId(String roleId) {
        this.remove(Wrappers.<RoleDataScopeDO>lambdaQuery()
                .eq(RoleDataScopeDO::getRoleId, roleId));
    }

    public List<RoleDataScopeDO> listByRoleIds(List<String> roleIds) {
        if (Tools.Coll.isBlank(roleIds)) {
            return new ArrayList<>();
        }
        return this.list(Wrappers.<RoleDataScopeDO>lambdaQuery()
                .in(RoleDataScopeDO::getRoleId, roleIds));
    }

    public List<String> listDataScopeCodeByRoleId(String roleId) {
        return this.listObjs(Wrappers.<RoleDataScopeDO>lambdaQuery()
                .select(RoleDataScopeDO::getDataScopeCode)
                .eq(RoleDataScopeDO::getRoleId, roleId), String.class::cast);
    }
}
